/*package com.sunyard.client2;

import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import com.sunyard.client.SunEcmClientApi;
import com.sunyard.client.bean.ClientBatchBean;
import com.sunyard.client.bean.ClientBatchFileBean;
import com.sunyard.client.bean.ClientBatchIndexBean;
import com.sunyard.client.bean.ClientFileBean;
import com.sunyard.client.bean.ClientHeightQuery;
import com.sunyard.client.impl.SunEcmClientWebserviceApiImpl;
import com.sunyard.ecm.server.bean.MigrateBatchBean;
import com.sunyard.util.OptionKey;

public class ClientTest {
	private Logger log = Logger.getLogger(Client.class);
	int socketPort = 8023;//DM
//	int socketPort = 8021;//UA
//	int socketPort = 8027;//DM 210 tomcat
	String ip = "172.16.3.252";
//	String ip = "172.16.3.210";
	int httpPort = 8080;
//	int httpPort = 8080;//210 tomcat
	String serverName = "SunECMDM"; // 内容存储服务工程名称
//	String serverName = "UnityAccess"; // 统一接入连接的服务工程名称
	String groupName = "b"; // 内容存储服务器组名
//	 SOCKET接口
//	SunEcmClientApi clientApi = new SunEcmClientSocketApiImpl(ip, socketPort);
//	 HTTP接口
//	SunEcmClientApi clientApi = new SunEcmClientHttpApiImpl(ip, httpPort, serverName);
	// WEBSERVICE接口
	SunEcmClientApi clientApi = new SunEcmClientWebserviceApiImpl(ip, httpPort, serverName);
	
	String userName = "admin";
	String passWord = "111";
	String validateResultTrue = "SUCCESS";//验证返回报文正确值
	String validateResultFail = "FAIL";//验证返回报文正确值
	String STARTDATE="20141202";//开始时间
	
	// =========================批次信息设定=========================
	String modelCode = "BWJDOC1"; // 内容模型代码
	String filePartName = "BWJPART1"; // 文档部件模型代码

//	String modelCode = "GUWEI_INDEX"; // 内容模型代码
//	String filePartName = "GUWEI_DOC"; // 文档部件模型代码
// 
//	String modelCode = "TEST_INDEX"; // 内容模型代码
//	String filePartName = "TEST_DOC"; // 文档部件模型代码
 
//	String modelCode = "JS_BUSI"; // 内容模型代码
//	String filePartName = "JS_IMG"; // 文档部件模型代码
	 
//	String contentID = "201311_12_nan"; //批次ID
	// 8位日期+随机路径+36位GUID+内容存储服务器ID
	String contentID = "201311_74_259C0726-393F-067C-5FB2-E38B46E4B6E9-3";
	String fileNO1 = "39AE5EA7-B8E4-F220-BE73-8E8319D0AA71";
	String fileNO2 = "";
	String fileNO3 = "381CA442-A7DC-1D11-59C0-9B493C997167";

	String annoID = "92E0A6BC-94CA-2F47-3EF3-A57FB34A69B5";

	String checkToken = "ea274068990be5e4a5c8"; // 检入检出随机数

	String token_check_value = "1234567890";
	String tokenCode = "468A95A803AC87A518DC58FB4E2F17C4";
	String insNo = "aag";
	// =========================批次信息设定=========================
	*//**
	 * 单元测试最主要的是：
	 * <ul>
	 * <li>测试数据的生成需要由代码生成</li>
	 * <li>测试数据使用完毕后由代码删除</li>
	 * <li>测试的结果判断由代码完成</li>
	 * <li>测试用例的覆盖要全</li>
	 * </ul>
	 *//*
	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	*//**
	 * 登录接口
	 *//*
	@Ignore
	@Test
	public void testLogin() {
		try {
//			// 验证正确用户名密码的登陆
			String resultMsg = "";
			resultMsg = clientApi.login(userName, passWord);
			log.debug("#######登录返回的信息[" + resultMsg + "]#######");
			Assert.assertEquals(validateResultTrue, resultMsg);
			
			// 验证admin用户已登录状态下再次登陆
//			resultMsg = clientApi.login(userName, passWord);
//			log.debug("#######登录返回的信息[" + resultMsg + "]#######");
//			Assert.assertEquals(validateResultTrue, resultMsg);
			
			// 验证错误用户名正确密码登陆
//			resultMsg = clientApi.login(userName + "error", passWord);
//			log.debug("#######登录返回的信息[" + resultMsg + "]#######");
//			Assert.assertEquals(validateResultFail, resultMsg);
			
			// 验证正确用户名错误密码登陆
//			resultMsg = clientApi.login(userName, passWord + "error");
//			log.debug("#######登录返回的信息[" + resultMsg + "]#######");
//			Assert.assertEquals(validateResultFail, resultMsg);
			
		} catch (Exception e) {
			Assert.assertFalse(true);
		}
	}
	
	*//**
	 * 登出接口
	 *//*
	@Ignore
	@Test
	public void testLogout() {
		try {
			// 验证正确用户名的登出
			String resultMsg = "";
			clientApi.login(userName, passWord); // admin用户进行登录
			resultMsg = clientApi.logout(userName);
			log.debug("#######登出返回的信息[" + resultMsg + "]#######");
			Assert.assertEquals(validateResultTrue, resultMsg);
			
//			// 验证正确用户名已经登出后的登出
//			resultMsg = clientApi.logout(userName);
//			log.debug("#######登出返回的信息[" + resultMsg + "]#######");
//			Assert.assertEquals(validateResultFail, resultMsg);
//			
//			// 验证正确用户名未登出错误用户名登出
//			clientApi.login(userName, passWord); // admin用户进行登录
//			resultMsg = clientApi.logout(userName + "error");
//			log.debug("#######登出返回的信息[" + resultMsg + "]#######");
//			Assert.assertEquals(validateResultFail, resultMsg);	
//			
//			// 验证正确用户名已登出错误用户名登出
//			resultMsg = clientApi.logout(userName + "error");
//			log.debug("#######登出返回的信息[" + resultMsg + "]#######");
//			Assert.assertEquals(validateResultFail, resultMsg);	
		}
		catch(Exception e) {
			Assert.assertFalse(true);
		}
	}
	
	
	 * 上传（指定批次号）接口
	 
	@Ignore
	@Test
	public void testUploadContentID() {
		ClientBatchBean clientBatchBean = new ClientBatchBean();
		clientBatchBean.setModelCode(modelCode);//索引ID
		clientBatchBean.setUser(userName);
		clientBatchBean.setPassWord(passWord);
		clientBatchBean.setBreakPoint(false); // 是否作为断点续传上传
		clientBatchBean.setOwnMD5(false); // 是否为批次下的文件添加MD5码

		// 若内容模型配置有安全校验
//		clientBatchBean.setToken_check_value(token_check_value);
//		clientBatchBean.setToken_code(tokenCode);

		// =========================设置索引对象信息开始=========================
		ClientBatchIndexBean clientBatchIndexBean = new ClientBatchIndexBean();
		//指定批次ID
		clientBatchIndexBean.setContentID(contentID);
		clientBatchIndexBean.setAmount("1");
		// 索引自定义属性
		clientBatchIndexBean.addCustomMap("START_TIME", STARTDATE);
		// =========================设置索引对象信息结束=========================

		// =========================设置文档部件信息开始=========================
		ClientBatchFileBean clientBatchFileBean = new ClientBatchFileBean();
		clientBatchFileBean.setFilePartName(filePartName);//文档ID
//		clientBatchFileBean.setFilePartName("ERROR");//文档ID
		// =========================设置文档部件信息结束=========================

		// =========================添加文件=========================
		ClientFileBean fileBean1 = new ClientFileBean();
		fileBean1.setFileName("E:\\image\\1.jpg");
		fileBean1.setFileFormat("jpg");
		
		clientBatchFileBean.addFile(fileBean1);
		// =========================添加文件=========================
		clientBatchBean.setIndex_Object(clientBatchIndexBean);
		clientBatchBean.addDocument_Object(clientBatchFileBean);
		try {
			String resultMsg = clientApi.upload(clientBatchBean, groupName);
			log.debug("#######上传批次返回的信息[" + resultMsg + "]#######");
//			Assert.assertEquals("732", resultMsg);
			String[] result = resultMsg.split("<<::>>");
			resultMsg = result[0];
			Assert.assertEquals(validateResultTrue, resultMsg);
//			Assert.assertEquals(validateResultFail, resultMsg);
		} catch (Exception e) {
			Assert.assertFalse(true);
		}
	}

	
	 * 上传（非指定批次号）接口
	 
//	@Ignore
	@Test
	public void testUpload() {
		ClientBatchBean clientBatchBean = new ClientBatchBean();
		clientBatchBean.setModelCode(modelCode);//索引ID
		clientBatchBean.setUser(userName);
		clientBatchBean.setPassWord(passWord);
		clientBatchBean.setBreakPoint(false); // 是否作为断点续传上传
		clientBatchBean.setOwnMD5(true); // 是否为批次下的文件添加MD5码

		// 若内容模型配置有安全校验
//		clientBatchBean.setToken_check_value(token_check_value);
//		clientBatchBean.setToken_code(tokenCode);

		// =========================设置索引对象信息开始=========================
		ClientBatchIndexBean clientBatchIndexBean = new ClientBatchIndexBean();
		//上传文件数
		clientBatchIndexBean.setAmount("2");
		// 索引自定义属性
		clientBatchIndexBean.addCustomMap("BUSI_DATE", STARTDATE);
		// =========================设置索引对象信息结束=========================

		// =========================设置文档部件信息开始=========================
		ClientBatchFileBean clientBatchFileBean = new ClientBatchFileBean();
		clientBatchFileBean.setFilePartName(filePartName);//文档ID
//		clientBatchFileBean.setFilePartName("ERROR");//文档ID
		// =========================设置文档部件信息结束=========================

		// =========================添加文件=========================
		ClientFileBean fileBean1 = new ClientFileBean();
		fileBean1.setFileName("R:/TEMP/2.jpg");
		fileBean1.setFileFormat("jpg");
		//文档自定义属性
//		fileBean1.addOtherAtt("START_TIME", "20131101");
//		fileBean1.addOtherAtt("START_TIME_ERROR", "20131002");
//		ClientFileBean fileBean2 = new ClientFileBean();
//		 fileBean2.setFileName("E:\\image\\2.jpg");
//		 fileBean2.setFileFormat("jpg");
		// 文件自定义属性
//		 fileBean1.addOtherAtt("IDCARD","330301198811048888");
		// fileBean2.setFilesize("123"); // 设置大小图的时候
		 ClientFileBean fileBean3 = new ClientFileBean();
		 fileBean3.setFileName("R:/TEMP/3.png");
		 fileBean3.setFileFormat("png");

		clientBatchFileBean.addFile(fileBean1);
//		clientBatchFileBean.addFile(fileBean2);
		clientBatchFileBean.addFile(fileBean3);
		// =========================添加文件=========================
		clientBatchBean.setIndex_Object(clientBatchIndexBean);
		clientBatchBean.addDocument_Object(clientBatchFileBean);
		try {
			String resultMsg = clientApi.upload(clientBatchBean, groupName);
			log.debug("#######上传批次返回的信息[" + resultMsg + "]#######");
//			Assert.assertEquals("732", resultMsg);
			String[] result = resultMsg.split("<<::>>");
			resultMsg = result[0];
			Assert.assertEquals(validateResultTrue, resultMsg);
//			Assert.assertEquals(validateResultFail, resultMsg);
		} catch (Exception e) {
			Assert.assertFalse(true);
		}
	}

	
	 * 检出接口
	 
	@Ignore
	@Test
	public void testCheckOut() {
		ClientBatchBean clientBatchBean = new ClientBatchBean();
		clientBatchBean.setModelCode(modelCode);
		clientBatchBean.setUser(userName);
		clientBatchBean.setPassWord(passWord);
		clientBatchBean.getIndex_Object()
				.addCustomMap("START_TIME", STARTDATE);
		clientBatchBean.getIndex_Object().setContentID(contentID+"aa");

		try {
			String checkTo = clientApi.checkOut(clientBatchBean, groupName);
			log.debug("#######检出返回的信息[" + checkTo + "]#######");
			String resultMsg = "";
			String[] result = checkTo.split("<<::>>");
			resultMsg = result[0];
			Assert.assertEquals(validateResultTrue, resultMsg);
		} catch (Exception e) {
			Assert.assertFalse(true);
		}
	}

	*//**
	 * 更新时需要注明版本号则表示自第几个版本更新,
	 * ------------------------------------------------------- 没有版本控制则无需注明
	 * 更新接口
	 *//*
	@Ignore
	@Test
	public void testUpdate() {
		ClientBatchBean clientBatchBean = new ClientBatchBean();
		clientBatchBean.setModelCode(modelCode);
		clientBatchBean.setUser(userName);
		clientBatchBean.setPassWord(passWord);
		clientBatchBean.getIndex_Object().setContentID(contentID);
//		clientBatchBean.getIndex_Object().addCustomMap("START_TIME", "20130824");
		clientBatchBean.getIndex_Object().addCustomMap("START_TIME", STARTDATE);
//		clientBatchBean.getIndex_Object().addCustomMap("UPDATETIME",
//				"20130828114548");

		// 若内容模型配置有安全校验（动态令牌）
//		String oper = OperPermission.ADD + "," + OperPermission.UPD + ","
//		+ OperPermission.DEL + "," + OperPermission.QUY + ","
//		+ OperPermission.MAK;
//
//		try {
//			tokenCode = clientApi.getToken(
//			"http://172.16.3.32:9080/SunECMConsole", token_check_value,
//			userName, oper);
//		} catch (Exception e1) {
//			// TODO Auto-generated catch block
//			e1.printStackTrace();
//		}
////		tokenCode = clientApi.getToken();
//		clientBatchBean.setToken_check_value(token_check_value);
//		clientBatchBean.setToken_code(tokenCode);
		// 若内容模型配置有安全校验（静态令牌）
//		clientBatchBean.setToken_check_value(token_check_value);
//		clientBatchBean.setToken_code(tokenCode);
		
		
		ClientBatchFileBean batchFileBean = new ClientBatchFileBean();
		batchFileBean.setFilePartName(filePartName);

//		// 新增一个文件
//		ClientFileBean fileBean1 = new ClientFileBean();
//		fileBean1.setOptionType(OptionKey.U_ADD);
//		fileBean1.setFileName("E:\\image\\2.jpg");
//		fileBean1.setFileFormat("jpg");
//		batchFileBean.addFile(fileBean1);
		// //
		//		
		 // 替换一个文件
//		 ClientFileBean clientFileBean2 = new ClientFileBean();
//		 clientFileBean2.setOptionType(OptionKey.U_REPLACE);
//		 clientFileBean2.setFileNO("39AE5EA7-B8E4-F220-BE73-8E8319D0AA71");
//		 clientFileBean2.setFileName("E:\\image\\2.jpg");
//		 clientFileBean2.setFileFormat("jpg");
//		 clientFileBean2.addOtherAtt("SAVE_NAME", "ABC_file3");
//		 clientFileBean2.addOtherAtt("LOAN", "LOAN1111");
//		 batchFileBean.addFile(clientFileBean2);

		// 删除一个文件
		 ClientFileBean clientFileBean3 = new ClientFileBean();
		 clientFileBean3.setOptionType(OptionKey.U_DEL);
		 clientFileBean3.setFileNO("7ADBDD09-DFC4-2A00-3503-51EEC95BBA39");
		 batchFileBean.addFile(clientFileBean3);

		// // 修改文档部件字段
//		ClientFileBean clientFileBean = new ClientFileBean();
//		clientFileBean.setOptionType(OptionKey.U_MODIFY);
//		clientFileBean.setFileNO("B7F0E665-EB2E-A68C-0443-333C2BC80DC4");
//		clientFileBean.addOtherAtt("IMAGEPAGEID", "1");
//		batchFileBean.addFile(clientFileBean);
//		//		
		clientBatchBean.addDocument_Object(batchFileBean);
		try {
			String resultMsg = clientApi.update(clientBatchBean, groupName,
					true);
			log.debug("#######更新批次返回的信息[" + resultMsg + "]#######");
			String[] result = resultMsg.split("<<::>>");
			Assert.assertEquals(validateResultTrue,result[0]);
		} catch (Exception e) {
			Assert.assertFalse(true);
		}
	}

	
	 * 检入接口
	 
	@Ignore
	@Test
	public void testCheckIn() {
		ClientBatchBean clientBatchBean = new ClientBatchBean();
		clientBatchBean.setModelCode(modelCode);
		clientBatchBean.setUser(userName);
		clientBatchBean.setPassWord(passWord);
		clientBatchBean.getIndex_Object()
				.addCustomMap("START_TIME", STARTDATE);
		clientBatchBean.getIndex_Object().setContentID(contentID);
		clientBatchBean.setCheckToken(checkToken);

		try {
			String resultMsg = clientApi.checkIn(clientBatchBean, groupName);
			String[] result = resultMsg.split("<<::>>");
			log.debug("#######检入返回的信息[" + resultMsg + "]#######");
//			System.out.println(result[0]);
			Assert.assertEquals(validateResultTrue, result[0]);
		} catch (Exception e) {
			Assert.assertFalse(true);
		}
	}

	
	 * 删除接口
	 
	@Ignore
	@Test
	public void testDelete() {
		ClientBatchBean clientBatchBean = new ClientBatchBean();
		clientBatchBean.setModelCode(modelCode);
		clientBatchBean.setPassWord(passWord);
		clientBatchBean.setUser(userName);
		clientBatchBean.getIndex_Object().setContentID(contentID);
		clientBatchBean.getIndex_Object().addCustomMap("START_TIME", STARTDATE);
		// 若内容模型配置有安全校验
//		clientBatchBean.setToken_check_value(token_check_value);
//		clientBatchBean.setToken_code(tokenCode);

		try {
			String resultMsg = clientApi.delete(clientBatchBean, groupName);
			log.debug("#######删除批次返回的信息[" + resultMsg + "]#######");
			String result[] = resultMsg.split("<<::>>");
			if(result.length>1)
			{
				resultMsg = result[1];
			}
			Assert.assertEquals(validateResultTrue, resultMsg);
		} catch (Exception e) {
			Assert.assertFalse(true);
		}
	}
	
	
	 * 高级查询接口
	 
	@Ignore
	@Test
	public void testHeightQuery() {
		ClientHeightQuery heightQuery = new ClientHeightQuery();
		heightQuery.setUserName(userName);
		heightQuery.setPassWord(passWord);
		heightQuery.setLimit(1000);
		heightQuery.setPage(1);
		heightQuery.setModelCode(modelCode);
		heightQuery.addCustomAtt("START_TIME", STARTDATE);
//		heightQuery.addCustomAtt("START_TIME_ERROR", "20131030");
		
		try {
			String resultMsg = clientApi.heightQuery(heightQuery, groupName);
			String[] result = resultMsg.split("<<::>>");
			log.debug("#######调用高级搜索返回的信息[" + resultMsg + "]#######");
			Assert.assertEquals("0001", result[0]);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	 * 查询接口
	 
	@Ignore
	@Test
	public void testQuery(){
		ClientBatchBean clientBatchBean = new ClientBatchBean();
		clientBatchBean.setModelCode(modelCode);
		clientBatchBean.setUser(userName);
		clientBatchBean.setPassWord(passWord);
		clientBatchBean.setDownLoad(true);
//		clientBatchBean.getIndex_Object().setVersion("1");
		clientBatchBean.getIndex_Object().setContentID("201311_74_259C0726-393F-067C-5FB2-E38B46E4B6E9-3");
		clientBatchBean.getIndex_Object()
		.addCustomMap("START_TIME",STARTDATE);

		// clientBatchBean.getIndex_Object().addCustomMap("VARCHARTYPE",
		// "varchartype");
		// 若内容模型配置有安全校验
//		clientBatchBean.setToken_check_value(token_check_value);
//		clientBatchBean.setToken_code(tokenCode);

		String resultMsg;
		try {
			resultMsg = clientApi.queryBatch(clientBatchBean, groupName);
			log.debug("查询结果报文："+resultMsg);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	
	 * 负载均衡接口
	 
	@Ignore
	@Test
	public void testInquireDMByGroup() {
		try {
			String resultMsg = clientApi.inquireDMByGroup(userName, "a");
			log.debug("#######客户端获取内容存储服务器信息[" + resultMsg + "]#######");
			String result[] = resultMsg.split("<<::>>");
			Assert.assertEquals("0001", result[0]);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Ignore
	@Test
	*//**
	 * 客户端调用立即迁移接口 -------------------------------------------------------
	 *//*
	public void immedMigrate() {
		MigrateBatchBean m = new MigrateBatchBean();
		m.setMigrate(true);
		m.setModelCode(modelCode);
		m.setUserName(userName+"aa");
		m.setPassWord(passWord+"aa");
		m.getIndex_Object().setContentID(contentID);
		m.getIndex_Object().addCustomMap("STARTDATE", STARTDATE);
		try {
			String resultMsg = clientApi.immedMigrate(m, groupName);
			String result[] = resultMsg.split("<<::>>");
			if(result.length>1)
				resultMsg = result[1];
			System.out.println(resultMsg);
			Assert.assertEquals(validateResultTrue, resultMsg);
		} catch (Exception e) {
			Assert.assertFalse(true);
		 
		}
	}
}
*/